module.exports =function($http,httpservice,$q){
  var contractLibraryService={
    findTemplateInfo:findTemplateInfo,
    tempDownload:tempDownload,
    findTemplateDetail:findTemplateDetail,
    findUserTemplateCollectionList:findUserTemplateCollectionList,
    findUserTemplateCollectStatistics:findUserTemplateCollectStatistics,
    insertUserTemplateCollect:insertUserTemplateCollect,
    deleteUserTemplateCollect:deleteUserTemplateCollect,
    //获取 合同列表
    findTemplatePageList:findTemplatePageList,
    findTemplateList:findTemplateList,
    queryDictTreeData: queryDictTreeData,
    findTemplateInfo:findTemplateInfo
  };

  //获取模板信息
  function findTemplateInfo(params) {
    return $http({
      url: httpservice.findTemplateInfoUrl,
      method: "POST",
      data:params,
      headers: {'Content-Type': 'application/json'}
    })
  }

  //下载模板
  function tempDownload (params) {
    return $http({
      method:"POST",
      url:httpservice.downloadTemplateUrl,
      params:params,
      responseType: 'arraybuffer',
      headers:{'Content-Type':'application/json'},
    })
  };

  //模板详情
  function findTemplateDetail (params) {
    return $http({
      url: httpservice.findTemplateDetailUrl,
      method: "POST",
      data:params,
      headers: {'Content-Type': 'application/json'}
    })
  }

  //我的合同收藏列表
  function findUserTemplateCollectionList (params) {
    return $http({
      url: httpservice.findUserTemplateCollectionListlUrl,
      method: "POST",
      data:params,
      headers: {'Content-Type': 'application/json'}
    })
  }

  //我的合同统计
  function findUserTemplateCollectStatistics () {
    return $http({
      url: httpservice.findUserTemplateCollectStatisticsUrl,
      method: "POST",
      data:{},
      headers: {'Content-Type': 'application/json'}
    })
  }

  //收藏模板
  function insertUserTemplateCollect (params) {
    return $http({
      url: httpservice.insertUserTemplateCollectUrl,
      method: "POST",
      data:params,
      headers: {'Content-Type': 'application/json'}
    })
  }

  //取消收藏模板
  function deleteUserTemplateCollect (params) {
    return $http({
      url: httpservice.deleteUserTemplateCollectUrl,
      method: "POST",
      data:params,
      headers: {'Content-Type': 'application/json'}
    })
  }





  function findTemplatePageList(data){
    var deferred = $q.defer();
    $http({
      method: 'POST',
      url: httpservice.findTemplatePageListUrl,
      data: data,
      headers: {'Content-Type': 'application/json'}
    }).then(function successCallback(response) {
      deferred.resolve(response.data);
    }, function errorCallback(response) {
      deferred.reject(response);
    });
    return deferred.promise;

  }
  function findTemplateList(keyword){
    var deferred = $q.defer();
    var params={
      keyword:keyword
    }
    $http({
      method: 'POST',
      url: httpservice.findTemplateListUrl,
      data: params,
      headers: {'Content-Type': 'application/json'}
    }).then(function successCallback(response) {
      deferred.resolve(response.data);
    }, function errorCallback(response) {
      deferred.reject(response);
    });
    return deferred.promise;

  }
  function queryDictTreeData(parentId){
    var deferred = $q.defer();
    var params={
      parentId:parentId
    }
    $http({
      method: 'POST',
      url: httpservice.queryDictTreeDataUrl,
      data: params,
      headers: {'Content-Type': 'application/json'}
    }).then(function successCallback(response) {
      deferred.resolve(response.data);
    }, function errorCallback(response) {
      deferred.reject(response);
    });
    return deferred.promise;

  }



  return contractLibraryService;
};
